#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e5 + 10;
int v[N], w[N];
int f[N];
int a[110], b[110];
int n, m;
int main()
{
	while (scanf("%d%d",&n,&m)==2 && n + m) {
		/*memset(f, 0, sizeof(f));
		memset(v, 0, sizeof(v));
		memset(w, 0, sizeof(w));*/
		for (int i = 1; i <= m; i++) {
			f[i] = 0, v[i] = 0, w[i] = 0;
		}
		for (int i = 1; i <= n; i++)scanf("%d", &a[i]);
		for (int i = 1; i <= n; i++)scanf("%d", &b[i]);
		int cnt = 0;
		for (int i = 1; i <= n; i++) {
			int k = 1;
			int c = b[i];
			while (k <= c) {
				v[++cnt] = a[i] * k;
				c -= k;
				k <<= 1;
			}
			if (c) {
				v[++cnt] = a[i] * c;
			}
		}
		f[0] = 1;
		for (int i = 1; i <= cnt; i++) {
			for (int j = m; j >= v[i]; j--) {
				f[j] |= f[j - v[i]];
			}
		}
		int ans = 0;
		for (int i = 1; i <= m; i++) {
			ans += f[i];
		}
		printf("%d\n", ans);
	}
	return 0;
}